/*
 * Created on Oct 15, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package com.erclab.internal.xpresso.formelements;

import java.util.Enumeration;
import java.util.Properties;

import com.erclab.internal.xpresso.exceptions.FormException;
import com.erclab.internal.xpresso.forms.Form;
import com.xpresso.utils.props.PropertyWorker;

/**
 * @author rodrigen
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class SimpleInputBox extends SimpleTextDisplay {

	protected String maxLength;
	protected String inputBoxSize;

	/* (non-Javadoc)
	 * @see com.erclab.internal.xpresso.formelements.FormElement#toHTML(com.erclab.internal.xpresso.forms.Form, com.erclab.internal.xpresso.forms.FormParameters)
	 */
	public String toHTML(Form theForm) {
		StringBuffer sb = new StringBuffer();
		sb.append("<INPUT TYPE=\"text\" name=\"Field");
		sb.append(this.idFormElement);
		sb.append("\"");
		sb.append(" id=\"" + this.destinationColumn + "\" ");
		if (theForm.getFormParameters().getAction().equals("update")){
			if(originalValue != null){
				sb.append("value=\"" + originalValue + "\" ");
			}
		} else {
			if(lookupValue != null){
				sb.append("value=\"" + this.lookupValue + "\" ");
			}
			 
		}
		
		setTagProperties(sb);
		
		sb.append("onChange=\"formElementChanged(this)\">");
				
		return sb.toString();
	}

	/**
	 * @param sb
	 */
	protected void setTagProperties(StringBuffer sb) {
		if(this.parameters == null || this.parameters.equals("") || this.parameters.startsWith("<"))
			return;
		
		Properties props = this.getElementParameters();
		
		Enumeration enumeration = props.propertyNames();
		while( enumeration.hasMoreElements() )
		{
			String key = (String)enumeration.nextElement();
			sb.append(" " + key + "=\"" + props.getProperty( key ) + "\" ");
		}
	}

	protected Properties getElementParameters(){
		return new PropertyWorker().getProperties(this.parameters);
	}
	

	/* (non-Javadoc)
	 * @see com.erclab.internal.xpresso.formelements.FormElement#loadLookupValues(com.erclab.internal.xpresso.forms.FormParameters)
	 */
	public void loadLookupValues(Form theForm)throws FormException {
		super.loadLookupValues(theForm);
	}

	/* (non-Javadoc)
	 * @see com.erclab.internal.xpresso.formelements.FormElement#isModifiable()
	 */
	public boolean isModifiable() {
		return true;
	}


}
